package com.jadesoft.ciadapter.plugin;

import javax.servlet.ServletRequest;

import com.jadesoft.ciadapter.library.JdPageHelper;
import com.jadesoft.ciadapter.plugin.base.DefaultPageAction;
import com.jadesoft.ciadapter.plugin.base.Pluggable;
import com.jadesoft.ciadapter.plugin.base.PluginAction;
import com.jadesoft.ciadapter.plugin.base.PluginManager;
import com.ufida.leaf.exception.BusinessException;

public class OzhMenuPlugin implements Pluggable {
	ServletRequest request = null ;
	public void init(Object container) {
		if ( ! (container instanceof ServletRequest)){
			throw new BusinessException("invalid container");
		}
		this.request = (ServletRequest)container ;
		JdPageHelper helper = JdPageHelper.getHelper(request);
		helper.css_enqueue("ozhmenu/menu");
		
		PluginAction menu = new DefaultPageAction(this.request){
			public Object exec(Object... args) {
				return getMenu();
			}
		};
		PluginManager.addAction("after_header", menu,container);
	}

	private String getMenu(){
		String menu = "";
		try {
			menu = JdPageHelper.loadTemplate("ozh_menu.ftl", null, null, this.request);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return menu ;
	}

}
